<?php
function loadSchemasFrom($dirPath) {
  $dir = dir($dirPath);
  $schemas = array();

  while (false !== ($entry = $dir->read())) {
    if (substr_compare($entry,'.xml',-4) == 0) {
      array_push($schemas,loadXMLFromFile($dirPath.$entry,FALSE));
    }
  }
  $dir->close();
  return $schemas;
}

function getFilterFrom(DOMDocument $schemaDoc) {
  $filters = array();
  
  $schemaXPath = new DOMXPath($schemaDoc);
  $qResult = $schemaXPath->query(SCHEMA_XPATH_FILTERS);

  foreach($qResult as $result) {
    $tResult = $schemaXPath->query(SCHEMA_XPATH_COLNAME,$result);
    $colName = $tResult->item(0)->nodeValue;

    $tResult = $schemaXPath->query(SCHEMA_XPATH_VALUE,$result);
    $value = $tResult->item(0)->nodeValue;

    $filters[$colName] = $value;
  }

  return $filters;
}

function getTableNameFrom(DOMDocument $schema) {
  $tXPath = new DOMXPath($schema);

  $qResult = $tXPath->query(SCHEMA_XPATH_TABLENAME);
  return $qResult->item(0)->nodeValue;
}
?>